<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>宇成建筑</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="../statics/css/font.css">
    <link rel="stylesheet" href="../statics/plugins/layui/css/layui.css">
    <link rel="stylesheet" href="../statics/css/xadmin.css">
    <link rel="stylesheet" href="../statics/css/style.css">
    <style>
        .layui-inline{
            width:50% !important;
        }
        .layui-input-block{
            width:70% !important;
        }
        .save{
            width: 100px;
        }
        .layui-form-item{
            padding: 10px;
        }
    </style>
</head>

<body class='labelAuto'>
    <div class="x-nav">
        <span class="layui-breadcrumb">
            <a href="welcome.html">首页</a>
            <a href="javascript:;">系统管理</a>
            <a>
                <cite>通知公告管理</cite>
            </a>
        </span>
        <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
            onclick="location.reload()" title="刷新">
            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
        </a>
        <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right;margin-right:10px"
            onclick="window.history.go(-1)" title="后退">
            <i class="iconfontBlod" style="line-height:30px">&#xe74f;</i>
        </a>
    </div>
    <div class="layui-fluid">
        <div class="layui-d layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body search">
                        <form action="" class="layui-form">
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label">标题</label>
                                    <div class="layui-input-block">
                                        <input type="text" class="layui-input" id='title'>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-inline" style="width: 100% !important;">
                                    <label class="layui-form-label">内容</label>
                                    <div class="layui-input-block" style="height: auto;">
                                        <div id="contentDiv"></div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label">权限</label>
                                    <div class="layui-input-block" style="height: auto;">
                                        <select name="" id="selectList">
                                            <option value="null">-</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <button class='layui-btn save' type='button'>保存</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
<script src="../statics/plugins/layui/layui.js" charset="utf-8"></script>
<script src='../statics/plugins/jQuery-3.2.1/jquery-3.2.1.min.js'></script>
<script type="text/javascript" src="../statics/plugins/X-admin/xadmin.js"></script>
<script type="text/javascript" src="../statics/js/public.js?v=1129"></script>
<script src="../statics/plugins/wangEditor-3.1.1//release/wangEditor.min.js"></script>
<script type='text/html' id='toolbar'>
    <button class="layui-btn addPeople">添加</button>
</script>
<script type="text/javascript">
    layui.use(['form', 'layer', "table", "laydate"], function () {
        var table = layui.table;
        var form = layui.form;
        var laydate = layui.laydate;
        var layer = layui.layer;
        // 异步数据加载
        var id=Number(localStorage.getItem('editNotice_id'));
        var E = window.wangEditor;
        var editor2 = new E('#contentDiv');
        editor2.customConfig.uploadImgShowBase64 = true
        editor2.create();
        var quanxianId='';
        $.ajax({
            url: url + "/setting/notice/info",
            type: "POST",
            async: false,
            data: {
                id:id,
                token:getToken()
            },
            success: function(r) {
                if(r.code == 100000) {
                    editor2.txt.html(r.data.content);
                    $('#title').val(r.data.title);
                    quanxianId=r.data.projectId;
                } else {
                    tips('通知',r);
                }
            }
        })
        $.ajax({
            url: url + "/project/project/selectLists",
            type: "POST",
            async: false,
            data: {
                token:getToken()
            },
            success: function(r) {
                if(r.code == 100000) {
                    var option = '';
                    for(var i = 0; i < r.data.length; i++) {
                        option += `
                            <option value=${r.data[i].id} ${quanxianId==r.data[i].id?"selected":""} name=${r.data[i].status}>${r.data[i].name}</option>
                        `
                    }
                    $('#selectList').html('<option value="0">-</option>' + option);
                } else {
                    tips('项目下拉列表',r);
                }
            }
        })
        form.render();
        $('body').on('click','.save',function(){
            var projectId=$('#selectList option:selected').val();
            var title=$('#title').val();
            var content=editor2.txt.html();
            $.ajax({
                url: url + "/setting/notice/edit",
                type: "POST",
                async: false,
                data: {
                    id:id,
                    projectId:Number(projectId),
                    title:title,
                    content:content,
                    token:getToken()
                },
                success: function(r) {
                    if(r.code == 100000) {
                        tips('编辑公告信息',r);
                        setTimeout(function(){
                            window.location.href='notice.html';
                        },1000)
                    } else {
                        tips('编辑公告信息',r);
                    }
                }
            })
        })
    });
</script>

</html>